package edu.njust.httpmanager.common;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class EmailTemplate {

    /**
     * 验证码主体邮件模板
     * @param recipient 用户姓名
     * @param verificationCode 验证码
     * @param expirationMinutes 有效期：分钟
     * @param senderName 发送人
     * @return
     */
    public static String generateVerificationEmail(String recipient, String verificationCode, int expirationMinutes, String senderName) {
        String template = "Dear [Recipient],\n\n" +
                "您的验证码为：[VerificationCode]\n" +
                "请在 [ExpirationTime] 内使用该验证码完成验证。\n\n" +
                "如果您没有请求此验证码，请忽略此邮件。\n\n" +
                "谢谢！\n" +
                "[YourName]";

        // 替换模板中的变量
        template = template.replace("[Recipient]", recipient);
        template = template.replace("[VerificationCode]", verificationCode);

        // 计算验证码过期时间
        LocalDateTime expirationTime = LocalDateTime.now().plusMinutes(expirationMinutes);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String expirationTimeString = expirationTime.format(formatter);
        template = template.replace("[ExpirationTime]", expirationTimeString);

        template = template.replace("[YourName]", senderName);

        return template;
    }
}
